<include file="__THEME__/header" />
<script type="text/javascript" src="__PUBLIC__/js/jquery.form.js"></script>
<script type="text/javascript" src="../Public/js/miniblog.js"></script>


<div class="Share radius5">
    <div  style="padding-bottom:10px"><span class="right lh20" id="_widget_weibo_words_count" >还可以输入<span class="f18px"><strong>140</strong></span>个汉字</span><span class="f14px" style="color:#008800">分享到我的微博，顺便说点什么吧</span></div>
    <div class="Share_box">
        <textarea id="_widget_weibo_content" name="content" class="Share_textarea">{$content}</textarea>
    </div>
	<div style="margin:0 0 0 12px;"> <span>添加：</span>
	    <a href="javascript:void(0)" target_set="_widget_weibo_content" onclick="ui.emotions(this);" class="a52"><img class="icon_add_face_d" src="__THEME__/images/zw_img.gif" />表情</a>
	</div>
    <php>if($type==1 && file_exists('./data/uploads/'.$type_data)) {</php>
    <div class="Share_Preview">
     	<img src="__ROOT__/thumb.php?w=200&h=200&t=f&url=./data/uploads/{$type_data}" />
    </div>
    <php>}</php>
    <div class="mt10">
   	  <input type="button" onclick="_widget_weibo_do_post()" id="_widget_weibo_post_button" class="btn_b right" value="分享">
      <!-- <a href="#">获取分享按钮</a> -->
    </div>
</div>
      

<script>
$(document).ready(function(){
	var $_widget_weibo_content = $("#_widget_weibo_content");
	var Interval;
	$_widget_weibo_content.keypress(function(event){
		var key = event.keyCode?event.keyCode:event.which?event.which:event.charCode;
        if (key == 27) {
        	clearInterval(Interval);
        }
    	_widget_weibo_check_words_count(this,<php> echo $ts['site']['length']; </php>);
    }).blur(function(){
		clearInterval(Interval);
    	_widget_weibo_check_words_count(this,<php> echo $ts['site']['length']; </php>);
    }).focus(function(){
		//微博字数监控
		clearInterval(Interval);
	    Interval = setInterval(function(){
	    	_widget_weibo_check_words_count('#_widget_weibo_content',<php> echo $ts['site']['length']; </php>);
		},300);
	});;
	
	_widget_weibo_check_words_count($_widget_weibo_content,<php> echo $ts['site']['length']; </php>);
	$_widget_weibo_content.focus();
    shortcut('ctrl+return', function(){_widget_weibo_do_post();clearInterval(Interval);},{'target':'_widget_weibo_content'});

	var url = "{:U('home/User/searchTips')}";
	userAutoTips({id:'_widget_weibo_content', url:url});
});

function _widget_weibo_do_post() {
	var content = $('#_widget_weibo_content').val();
	var type = '{$type}';
	var typedata = '{$type_data}';
	var source = '{$source|addslashes}';
	var sourceUrl = '{$sourceUrl}';
	var $_widget_weibo_post_button = $('#_widget_weibo_post_button');
	$_widget_weibo_post_button.attr('disabled', 'true');
	$.post(U('home/Widget/doShare'),{content:content,type:type,typedata:typedata,source:source,sourceUrl:sourceUrl},function(res){
		if(res=='1'){
			ui.success('分享成功');
			setTimeout(function(){self.location=U('home/User/index');}, 1000);
		}else {
			ui.error('分享失败');
		}
		$_widget_weibo_post_button.removeAttr('disabled');
	});
}

function _widget_weibo_check_words_count(obj,num) {
	var len = $(obj).val().length;
	var post_button_obj = $('#_widget_weibo_post_button');
	var word_count_obj  = $('#_widget_weibo_words_count');
	
    if(len==0){
        post_button_obj.attr('disabled',true).attr('class','btn_b_disable');
        word_count_obj.html('你还可以输入<span class="f18px"><strong>'+ (num-len) + '</strong></span>字');
    }else if( len > num ){
        post_button_obj.attr('disabled',true).attr('class','btn_b_disable');
        word_count_obj.css('color','red').html('已超出<span class="f18px"><strong>'+ (len-num) +'</strong></span>字');
    }else if( len <= num ){
        post_button_obj.removeAttr('disabled').attr('class','btn_b right');
        word_count_obj.css('color','#999').html('你还可以输入<span class="f18px"><strong>'+ (num-len) + '</strong></span>字');
    }
}
</script>